<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>ES6 生成器函数</title>
  </head>
  <body>
    <h1>Generator 生成器函数</h1>
    <script>
      function* range(count, start = 1) {
        for (let i = start; i < start + count; i++) yield i;
      }

      console.log([...range(100)]);

      //
      class 形状 {
        constructor(n) {
          this.n = n;
        }
        toString() {
          return `我是${this.n}边形！`;
        }
      }
      class 矩形 extends 形状 {
        constructor(l, w) {
          super(4);
          this.l = l;
          this.w = w;
        }
        area() {
          return this.l * this.w;
        }
      }
      class 正方形 extends 矩形 {
        constructor(w) {
          super(w, w);
        }
      }

      let shape = new 正方形(4);
      console.log(shape.toString(), shape.area());
    </script>
  </body>
</html>
